import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

/**
 * 所有角色都能够访问该路由下的信息
 * */
export const constantRoutes = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login.vue'),
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('@/views/register.vue'),
  },
  {
    path: '/404',
    component: () => import('@/views/404.vue'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'index',
    children:[
      {
        path: 'index',
        component: () => import('@/views/index'),
        name: 'Index',
      },
      {
        path: 'staging',
        component: () => import('@/views/staging/index'),
        name: 'Staging',
      },
      {
        path: 'user',
        component: () => import('@/views/user/index'),
        name: 'User',
      },
    ]
  },

  {
    // 个人设置页面
    path: '/user/setting',
    name: 'Setting',
    component: () => import('@/views/user/setting/index'),
  },
  {
    // 修改密码页面
    path: '/user/setting/password',
    name: 'Password',
    component: () => import('@/views/user/setting/password/index'),
  },
  {
    // 修改个人信息页面
    path: '/user/setting/info',
    name: 'Info',
    component: () => import('@/views/user/setting/info/index'),
  },
  {
    // 上传学生证页面
    path: '/user/setting/upload',
    name: 'Upload',
    component: () => import('@/views/user/setting/upload/index'),
  },
  { path: '*', redirect: '/404', hidden: true },
]

/**
 * 该路由信息由用户角色进行控制显示 (该路由是查询当前登录角色拥有的哪些菜单信息)
 * */
export const asyncRoutes = [

]

const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
